package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.ThemeCatalog;
import cn.wolfcode.trip.base.mapper.ThemeCatalogMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IThemeCatalogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 礼品卡主题目录业务实现类
 */
@Service
public class ThemeCatalogServiceImpl implements IThemeCatalogService {

    @Autowired
    private ThemeCatalogMapper themeCatalogMapper;

    /**
     * 新增和编辑
     * @param
     */
    public void saveOrUpdate(ThemeCatalog themeCatalog) {
        if(themeCatalog.getId()!=null){
            themeCatalogMapper.updateByPrimaryKey(themeCatalog);
        }else{
            themeCatalogMapper.insert(themeCatalog);
        }
    }

    /**
     * 查询所有主题
     * @return
     */
    public List<ThemeCatalog> listAll() {
        return themeCatalogMapper.selectAll();
    }

    /**
     * 分页
     * @param qo
     * @return
     */
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<ThemeCatalog> list = themeCatalogMapper.selectForList(qo);
        return new PageInfo(list);
    }

}
